package com.cnhaimei.vod.net.dc;

import java.security.PublicKey;
import java.sql.Struct;
import java.util.ArrayList;
import java.util.List;

import android.R.integer;

public class CallService {
	private static final CallService mG = new CallService();
	private ArrayList<String> mList = null;
	
	private CallService() {
		mList = new ArrayList<String>();
	}

	public static CallService G() {
		return mG;
	}

	public List<String> getItems() {
		return mList;
	}
	
	public void addItem(String strItem) {
		if (mList != null) {
			int i = 0;
			for (; i < mList.size(); i++) {
				if (mList.get(i).equals(strItem)) {
					return;
				}
			}
			if (i >= mList.size()) {
				mList.add(strItem);
			}
		}
	}

	public void addItems(String[] items) {
		if (mList != null) {
			for (String item : items) {
				int i = 0;
				for (; i < mList.size(); i++) {
					if (mList.get(i).equals(item)) {
						return;
					}
				}
				if (i >= mList.size()) {
					mList.add(item);
				}
			}
		}
	}
	
	public void clearItems() {
		if (mList != null) {
			mList.clear();
		}
	}
	
	public boolean hasItems() {
		return mList != null && mList.size() > 1;
	}
		
	public ServiceItem parse(String item) {
		int index = -1;
		String name = "";
		int i = item.indexOf('|');
		if (i > 0) {
			try {
				index = Integer.parseInt(item.substring(0, i));
				name = item.substring(i + 1);
			} catch (Exception e) {
				// TODO: handle exception
			} 
		}
		
		return new ServiceItem(index, name);
	}
	
	public class ServiceItem {
		public ServiceItem(int index, String name){
			mIndex = index;
			mName = name;
		};
		
		public int getIndex() {
			return mIndex;
		}
		
		public String getName() {
			return mName;
		}
		
		int mIndex;
		String mName;
	}
}
